home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / risc_src.lha / risc_sources / pmax / pmaxassist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-23  |  3.4 KB  |  145 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <syscall.h>
  4. #include <sys/sysmips.h>
  5. #include <machine/cachectl.h>
  6. #include <nlist.h>
  7.  
  8. #define IF ((
  9. #define THEN )?(
  10. #define ELSE ):(
  11. #define FI ))
  12.  
  13. #define MIN_HEAP_SIZE 524288  /* .5 Mb */
  14. #define DEFAULT_HEAP_SIZE 4096000 /* 4 Mb  */
  15. #define STDIO_SPACE   49152   /* be sure to save 48k of data space for stdio */
  16. #define STATIC_SPACE  131072  /* .125Mb for fun, usr "-l" to add to this */
  17. #define SAVED_SPACE   (STDIO_SPACE+STATIC_SPACE)
  18.  
  19.  
  20. main( argc, argv )
  21. char **argv;
  22. int argc;
  23. {
  24.     long heap_wanted = -1;
  25.     long leave_wanted = -1;
  26.     long debug = 0;
  27.  
  28.     long
  29.     heap_size;
  30.               
  31.     long
  32.     total,
  33.     aligned_total,
  34.     aligned_heap_size;
  35.  
  36.     char **av;
  37.  
  38.     av = argv;
  39.     av[argc] = 0; /* easy end test */
  40.  
  41.     while (*av)  {
  42.     if ( ( !strcmp( *av, "-h" ) ) || ( !strcmp( *av, "-heap" ) ) )
  43.         heap_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  44.     else if ( ( !strcmp( *av, "-l" ) ) || ( !strcmp( *av, "-leave" ) ) )
  45.         leave_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  46.     else if (!strcmp( *av, "-d" ) )
  47.         debug = -1;
  48.     av++;
  49.     }
  50.  
  51.     /* Compute max allowed heap size.  MIN in case datasize is big. */
  52.     /*  Quad align. */
  53.  
  54.                    
  55.     /* decide what to allocate - give user his request if it's within reason */
  56.  
  57.     if ((heap_wanted == -2))
  58.     heap_size = DEFAULT_HEAP_SIZE;
  59.     else                      
  60.     if (heap_wanted == -1)
  61.     heap_size = DEFAULT_HEAP_SIZE;
  62.     else
  63.     if (heap_wanted > MIN_HEAP_SIZE)
  64.     heap_size = heap_wanted;
  65.     else
  66.     heap_size = MIN_HEAP_SIZE;
  67.  
  68.     total = sbrk( heap_size * 2 );
  69.     if (total == -1)  {
  70.     printf( "T could not allocate two heaps of %d bytes.\n", heap_size);
  71.     printf( "Please retry with smaller heaps by using the -h switch.\n");
  72.     exit(1);
  73.     }
  74.         
  75.     /* make heaps smaller (if necessary) for quadword alignment */
  76.  
  77.     aligned_total = (total + 15) & 0xFFFFFFF0;
  78.     aligned_heap_size = ( ((heap_size * 2) - (aligned_total - total))
  79.               & 0xFFFFFFC0 );
  80.  
  81.     heap_size = aligned_heap_size / 2;
  82.  
  83.     /* print message if any command line flag is given */
  84.  
  85.     if ( (heap_wanted != -1) || (leave_wanted != -1) )
  86.     printf( "%d bytes per heap, %d bytes reserved\n",
  87.         heap_size, leave_wanted + STATIC_SPACE );
  88.  
  89.     start_t( aligned_total, (aligned_total + heap_size), heap_size, 
  90.              argc, argv, debug);
  91.  
  92. }
  93.  
  94. gc_interrupt()
  95. {
  96.   printf("Interrupted during GC; 'q' to exit, anything else to continue GC.\n");
  97.   if (getchar() == 'q')
  98.      exit(0);
  99. }
  100.  
  101. extern int errno;
  102. extern char *sys_errlist[];
  103. extern int sys_nerr;
  104.  
  105. get_unix_error_msg(t, size) 
  106. char *t;
  107. int size; 
  108. {
  109.   char *s;    
  110.   int i;
  111.  
  112.   i = 0;
  113.   s = (char *) sys_errlist[ errno ];
  114.   while (i<size && ((*t++ = *s++) != '\0')) i++; 
  115. }
  116.  
  117. flush_icache(addr,nbytes)
  118. char *addr;
  119. int nbytes;
  120. {
  121.   syscall(SYS_sysmips,MIPS_CACHEFLUSH,addr,nbytes,ICACHE,0);
  122. }
  123.  
  124. /*
  125.  * return the address of the function functionName in the namelist 
  126.  * of the file fileName.
  127.  * the calling procedure had better make sure that fileName exists.
  128.  */
  129. unsigned long
  130. nlistone(fileName,functionName)
  131. char *fileName, *functionName;
  132. {
  133. struct nlist nl[2];
  134. int rc;
  135.  
  136. nl[1].n_name = '\0'; /* terminate the name list */
  137. nl[0].n_name = functionName; /* put the function name in */
  138. rc = nlist(fileName,nl); /* call nlist */
  139. if (rc < 0 || (nl[0].n_type == (unsigned char) 0 /* check for errors */
  140.        && nl[0].n_value == (unsigned long) 0))
  141.     return ((unsigned long) 0);
  142. else
  143.     return(nl[0].n_value); /* return the address */
  144. }
  145.